Skip to content

fix(cli): parse module:object server specs in _parse_file_path - #3969

Open
mia03ther wants to merge 2 commits into
modelcontextprotocol:mainfrom
mia03ther:fix/3966-parse-file-path
Open

mia03ther wants to merge 2 commits into
modelcontextprotocol:mainfrom
mia03ther:fix/3966-parse-file-path

Conversation

@mia03ther

Copy link
Copy Markdown

Fixes #3966.

_parse_file_path() split the file spec on the last colon, so entry.py:pkg_srv:app became file entry.py:pkg_srv and failed with File not found — making the module:object branch of _import_server() unreachable from the CLI (mcp dev / run / install).

This splits on the first colon after the file path whose left side is an existing file, so the server object may itself contain a colon. A colon can also appear inside the file path, so each candidate split is checked for an existing file; when no split leaves an existing file it falls back to the last-colon split, so a genuinely missing file reports the same path as before.

Tests: added a entry.py:pkg_srv:app case to test_parse_file_path_accepts_valid_specs, plus a colon-in-directory case and a missing-file-with-module:object case. tests/cli/test_utils.py: 13 passed; src/mcp/cli/cli.py coverage 100%, ruff and pyright clean.

_parse_file_path split on the last colon, so entry.py:pkg_srv:app became
file entry.py:pkg_srv and failed with File not found, making the
module:object branch of _import_server unreachable from the CLI. Split on
the first colon after the file path whose left side is an existing file,
falling back to the last-colon split so missing files report the same path
as before.

Fixes modelcontextprotocol#3966

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Re-trigger cubic

Comment thread tests/cli/test_utils.py Resolved
Comment thread src/mcp/cli/cli.py Resolved
…path

If the whole file spec is an existing file, take it as-is instead of
splitting on its colons: a colon can be part of the file path itself.
Also skip the colon-in-directory tests on Windows, where ':' is not
allowed in directory names.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI _parse_file_path() splits with rsplit(":", 1), making _import_server()'s "module:object" syntax unreachable

1 participant